package thread;

public class ThreadWaiting {
    public static void main(String[] args) {
        Object o = new Object();
        Thread t1 = new Thread(()->{
            synchronized(o){
                System.out.println("等待之前");
                try {
                    o.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("等待之后");
            }
        });
        Thread t2 = new Thread(()->{
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            synchronized (o){
                System.out.println("唤醒之前");
                o.notify();
                System.out.println("唤醒之后");
            }
        });
        t1.start();
        t2.start();
    }
}
